<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="tutorial.css">
<TITLE>
What is a Constraint in Logic Programming?
</TITLE>
</HEAD>
<BODY >
<A HREF="tutorial098.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="tutorial100.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc197">14.1</A>&nbsp;&nbsp;What is a Constraint in Logic Programming?</H2>

Constraints fit very naturally into the Logic Programming paradigm.
Declaratively, a constraint is just the same as any other predicate.
Indeed, in ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP>, &#8220;constraints&#8221; are not a particular
programming language construct, constraints are just a conceptual notion.<BR>
<BR>
Consider the following standard Prolog query:
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
?- member(X, [5,7,3,4]), X =&lt; 4.
</PRE></BLOCKQUOTE>
This will succeed with X = 3 after some search.
In this example, both the member/2 goal and the inequality goal could
be considered `constraints on X' because they both restrict the
possible values for X. Usually, however, member/2 would not be considered
a &#8220;constraint&#8221; because of its backtracking (search) behaviour:
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
?- member(X, [5, 7, 3, 4]).
X = 5
More (0.00s cpu)
X = 7
More (0.04s cpu)
</PRE></BLOCKQUOTE>
Also, the standard Prolog inequality would not be considered a &#8220;constraint&#8221;,
because if invoked on its own it will raise an error:
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
?- X =&lt; 4.
instantiation fault in X =&lt; 4
</PRE></BLOCKQUOTE>
<A NAME="@default354"></A>
In the following, we will call a predicate a <B>constraint</B> only if it
<UL CLASS="itemize"><LI CLASS="li-itemize">
behaves deterministically
<LI CLASS="li-itemize">somehow actively enforces its declarative meaning
</UL>
<HR>
<A HREF="tutorial098.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="tutorial100.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
